/*
 * Copyright (c) 2018-2999 九五云信息科技有限公司 All rights reserved.
 *
 * https://www.gz-yami.com/
 *
 */

package com.yami.shop.multishop.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.yami.shop.bean.model.SmsRechargeLog;
import com.yami.shop.common.annotation.SysLog;

import javax.validation.Valid;

import com.yami.shop.common.util.PageParam;
import com.yami.shop.security.multishop.util.SecurityUtils;
import com.yami.shop.service.SmsRechargeLogService;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import lombok.AllArgsConstructor;


/**
 *
 *
 * @author lhd
 * @date 2020-07-05 16:19:10
 */
@RestController
@AllArgsConstructor
@RequestMapping("/multishop/smsRechargeLog" )
public class SmsRechargeLogController {

    private final SmsRechargeLogService smsRechargeLogService;

    /**
     * 分页查询
     * @param page 分页对象
     * @param smsRechargeLog
     * @return 分页数据
     */
    @GetMapping("/page" )
    public ResponseEntity<IPage<SmsRechargeLog>> getSmsRechargeLogPage(PageParam<SmsRechargeLog> page, SmsRechargeLog smsRechargeLog) {
        return ResponseEntity.ok(smsRechargeLogService.page(page, new LambdaQueryWrapper<SmsRechargeLog>().eq(SmsRechargeLog::getIsPayed,1)
                        .eq(SmsRechargeLog::getShopId, SecurityUtils.getShopUser().getShopId()).orderByDesc(SmsRechargeLog::getChargeTime)));
    }


    /**
     * 通过id查询
     * @param rechargeId id
     * @return 单个数据
     */
    @GetMapping("/info/{rechargeId}" )
    public ResponseEntity<SmsRechargeLog> getById(@PathVariable("rechargeId") Long rechargeId) {
        return ResponseEntity.ok(smsRechargeLogService.getById(rechargeId));
    }

    /**
     * 新增
     * @param smsRechargeLog
     * @return 是否新增成功
     */
    @SysLog("新增" )
    @PostMapping
    @PreAuthorize("@pms.hasPermission('multishop:smsRechargeLog:save')" )
    public ResponseEntity<Boolean> save(@RequestBody @Valid SmsRechargeLog smsRechargeLog) {
        return ResponseEntity.ok(smsRechargeLogService.save(smsRechargeLog));
    }

    /**
     * 修改
     * @param smsRechargeLog
     * @return 是否修改成功
     */
    @SysLog("修改" )
    @PutMapping
    @PreAuthorize("@pms.hasPermission('multishop:smsRechargeLog:update')" )
    public ResponseEntity<Boolean> updateById(@RequestBody @Valid SmsRechargeLog smsRechargeLog) {
        return ResponseEntity.ok(smsRechargeLogService.updateById(smsRechargeLog));
    }

    /**
     * 通过id删除
     * @param rechargeId id
     * @return 是否删除成功
     */
    @SysLog("删除" )
    @DeleteMapping("/{rechargeId}" )
    @PreAuthorize("@pms.hasPermission('multishop:smsRechargeLog:delete')" )
    public ResponseEntity<Boolean> removeById(@PathVariable Long rechargeId) {
        return ResponseEntity.ok(smsRechargeLogService.removeById(rechargeId));
    }

}
